﻿'*******************************************************************************
'*******************************************************************************
'** Copyright 2008 Robert Burke                                              ***
'** r.burke.itt@gmail.com                                                    ***
'**                                                                          ***
'** Licensed under the Apache License, Version 2.0 (the "License");          ***
'** you may not use this file except in compliance with the License.         ***
'** You may obtain a copy of the License at:                                 ***
'**                                                                          ***
'** http://www.apache.org/licenses/LICENSE-2.0                               ***
'**                                                                          ***
'** Unless required by applicable law or agreed to in writing, software      ***
'** distributed under the License is distributed on an "AS IS" BASIS,        ***
'** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. ***
'** See the License for the specific language governing permissions and      ***
'** limitations under the License.                                           ***
'*******************************************************************************
'*******************************************************************************

Imports Microsoft.Win32
Imports System.Net

Public Class frmSysTray
    Private WithEvents Client As New WebClient

    Private Sub TrayPad_State()
        TrayPad.Visible = Not TrayPad.Visible
        TrayPad.Activate()
    End Sub

    Public Sub FolderPad_State()
        FolderPad.Visible = Not FolderPad.Visible
        FolderPad.Activate()
    End Sub

    Private Sub NotifyIcon1_Click(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles NotifyIcon1.Click
        If e.Button = Windows.Forms.MouseButtons.Left Then
            If My.Settings.DefaultClick = 0 Then
                FolderPad_State()
            ElseIf My.Settings.DefaultClick = 1 Then
                TrayPad_State()
            End If
        End If
    End Sub

    Private Sub frmSysTray_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        GetWindowsVersion()

        If My.Settings.TrayPadLocation = New Point(-32000, -32000) Then
            My.Settings.TrayPadLocation = New Point(0, 0)
        End If

        If My.Settings.TrayPadStart = 1 Then
            TrayPad_State()
        End If

        Me.Hide()

        If Not System.IO.Directory.Exists(savePath) Then
            System.IO.Directory.CreateDirectory(savePath)
        End If

        ExistsAltap()
        ExistsNotepad()

        If My.Settings.SysPadUpdateNotify = 1 Then
            GetLatestVersionInfo()
        End If
    End Sub

    Private Sub mnuSettings_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuSettings.Click
        Dim Settings As New frmSettings
        Settings.ShowDialog()
    End Sub

    Private Sub mnuExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuExit.Click
        If MessageBox.Show("Are you sure you want to exit SysPad?", "Exit Confirmation", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) = Windows.Forms.DialogResult.OK Then
            Me.Dispose()
        End If
    End Sub

    Private Sub mnuShowFolderPad_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuShowFolderPad.Click
        FolderPad_State()
    End Sub

    Private Sub mnuShowTrayPad_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuShowTrayPad.Click
        TrayPad_State()
    End Sub

    Private Sub mnuAbout_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuAbout.Click
        frmAbout.ShowDialog()
    End Sub

    Private Sub mnuHelp_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuHelp.Click
        Try
            Process.Start(AppPath & "SysPad.chm")
        Catch ex As Exception
            MessageBox.Show("Could not launch the SysPad help file.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
        End Try
    End Sub

    Private Sub mnuCheckForUpdates_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuUpdates.Click
        Process.Start("SysPadAU.exe")
    End Sub
End Class